package com.quicklife.action.common;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.quicklife.service.impl.AboutMeServiceImpl;
import com.quicklife.service.impl.GetBusInfosServiceImpl;
import com.quicklife.service.inter.AboutMeService;
import com.quicklife.service.inter.GetBusInfosService;

public class GetBusInfosAction extends HttpServlet {

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 返回格式 
	 * {'address':'福建省福州市鼓楼区西洪路594号',
	 *	'id':50,'lat':26.085099,'lon':119.270185,'login_name':'xiaokonglong',
	 *	'logo':'/QuickLifeServer/upload\7c56dde6-668d-4193-a412-0af4f2d72137.jpg',
	 *	'name':'小恐龙','password':'','phone':'12332','roleid':1,
	 *	'score':0,'status':0,'type':0,'typename':'餐饮'}
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {


		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();

		String rtinfos = "";

		// 获得客户端请求参数
		String actionFlag=request.getParameter("actionflag");
		String rqInfos = request.getParameter("rqinfos");

		//创建服务
		GetBusInfosService busInfosService=new GetBusInfosServiceImpl();
		// 解析actionFlag，判断交给哪个处理
		if("busdetail".equalsIgnoreCase(actionFlag)){
			rtinfos=busInfosService.getBusInfosById(rqInfos);
		}else if("searchbus".equalsIgnoreCase(actionFlag)){
			rtinfos=busInfosService.searchBusInfosByLatLon(rqInfos);
		}else if("buscomm".equalsIgnoreCase(actionFlag)){
			rtinfos=busInfosService.getBusCommsById(rqInfos);
		}
		
		// 返回结果
		out.print(rtinfos);

		out.flush();
		out.close();
	}

}
